#ifndef FLIST_H__
#define FLIST_H__

#include "figure.h"

//------------------------------------------------------
struct FListItem
{
   Figure    * fig;
   FListItem * next;

   FListItem( FListItem * n = NULL, Figure * f = NULL )
   : fig(f), next(n)
   {}
};

//------------------------------------------------------
class FList : public FListItem
{
   friend std::ostream & operator << (std::ostream & s, FList & l);
   friend class FListIterator;

public:

   FList() : FListItem() {}
   ~FList() { clear(); }
   FList & add( Figure * f );
   FList & deltop();
   FList & clear();
   bool empty() { return NULL == next; }
};

//------------------------------------------------------
class FListIterator
{
   FListItem * item;

public:

   FListIterator( FList & l )               : item(&l) {}
   Figure * operator -> ()                  { if( !item->next ) return NULL;
                                              return item->next->fig; 
                                            }
   operator Figure * ()                     { return operator -> (); }
   FListIterator & operator ++ ()           { if( item->next ) item = item->next;
                                              return *this;
                                            }
   FListIterator & operator = ( FList & l ) { item = &l;
                                              return *this;
                                            }
   FListIterator & insert( Figure * f );
   FListIterator & remove();
};

#endif //FLIST_H__
